-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a Receiver.close()
method
#348
Conversation
Still need to add tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but the CI is failing, and this reminds me that it would be good to add tests at least for the receivers that actually do something when close()
is called.
And oh, yes! As usual names, names, names 😆
TL;DR: All good the name actually, just some other comments about future directions.
I was going to suggest to rename close()
to stop()
, for once to match the ReceiverStoppedError
but also to match the upcoming Service
interface.
But I see close actually wait for the current buffer to be consumed, my idea for stop()
would be that stuff gets just dropped.
Maybe to make it play better with Service
we can keep close()
as you implemented it, as a "graceful" shutdown, and when we introduce Service
we can use cancel()
to drop the current buffers. Then maybe stop()
can take an option to decide if close()
or cancel()
is called (stop is usually implemented as self.cancel(); await self
).
Yes, I'm already working on tests in this same branch, just made an early PR because the code is ready for review.
I think |
Mmm, receiver don't need to have task, but many do (like But maybe there are other solutions to this. We can discuss this when the time comes. |
Please let me know when this is ready for a final review :) |
That doesn't sound like an issue, because people still call And calling |
But If we make |
This is ready, the only big change is that |
Last push to have a (
|
BTW, the method can't be abstract, otherwise this is a breaking change. We need to provide a default empty implementation I guess. We can create an issue to make the method abstract for 2.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't review everything, because I think the review will change a lot depending on what we do with close
vs stop()
(stop()
being close()
/cancel()
+ __await__
).
cancel()
and __await__
are actually the 2 primitives used by (Background
)Service
too, based on Task
, and the more I look at it, the more I think receivers should follow this interface too.
87e95f9
to
1cdba55
Compare
I've made the
With this the two above concerns should also go away. |
1cdba55
to
283d182
Compare
Classes that implement the `Sender` or `Receiver` interfaces currently need to override the `send` or the `ready` and `consume` methods respectively. As we add more methods, to these interfaces, it becomes hard to track which methods are there for internal use and which ones are there to implement the interface. Using the `override` decorators helps with that. Signed-off-by: Sahas Subramanian <[email protected]>
Also implement the method in all classes implementing the `Receiver` interface. Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
Signed-off-by: Sahas Subramanian <[email protected]>
283d182
to
6e5d635
Compare
Rebased on latest |
@llucax could you take a look at this again? |
Once the receiver's buffer is drained, trying to receive a message will raise a | ||
[`ReceiverStoppedError`][frequenz.channels.ReceiverStoppedError]. | ||
""" | ||
raise NotImplementedError("close() must be implemented by subclasses") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we don't forget:
This method would allow individual receivers to be closed, without affecting the underlying channel, if there is one.